# # 可以重复拿东西
# N,V=map(int,input().split())
# dp=[[0]*(V+1) for i in range(N+1)]
#
# for i in range(1,N+1):
#     wi,vi=map(int,input().split())
#     for j in range(0,V+1):
#         if j<wi:
#             dp[i][j]=dp[i-1][j]
#         else:
#             dp[i][j]=max(dp[i-1][j],dp[i][j-wi]+vi)
# print(dp[N][V])

N,V=map(int,input().split())
dp=[0]*(V+1)

for i in range(1,N+1):
    wi,vi=map(int,input().split())
    for j in range(wi,V+1):
        dp[j]=max(dp[j],dp[j-wi]+vi)# 在dp[2wi]时，比较的是dp[wi]与dp[j]
print(dp[N][V])